package com.softeem.springboot04.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.softeem.springboot04.entity.User;
import com.softeem.springboot04.service.IUserService;
import com.softeem.springboot04.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
public class UserController {

    @Autowired
    private IUserService userService;

    @GetMapping("/login")
    public R login(User user){
        return userService.login(user);
    }

    @PostMapping("/reg")
    public R reg(User user){
        return userService.reg(user);
    }

    @GetMapping("/list")
    public R list(Integer page,Integer limit){
        //查询总记录数
        long count = userService.count();
        //执行分页查询
        List<User> list = userService.list(new Page(page,limit,count));
        return R.ok().setMsg("查询完成").setData(list).setCount(count);
    }
}
